package com.zkingsoft.service.impl;

import com.zkingsoft.service.BizStaffService;
import com.matrix.core.constance.SystemErrorCode;
import com.zkingsoft.bean.BizStaff;
import com.zkingsoft.common.bean.SysUsers;
import com.zkingsoft.dao.BizStaffDao;

import org.springframework.stereotype.Service;

import java.util.Map;

import com.matrix.core.constance.MatrixConstance;
import com.matrix.core.exception.GlobleException;
import com.matrix.core.pojo.PaginationVO;
import com.matrix.core.tools.ModelUtils;

import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

import com.matrix.core.tools.WebUtil;
import com.matrix.core.tools.UUIDUtil;

/**
 * @description service接口实现类(员工信息表)
 * @author 肖崇高
 * @date 2018-05-23 20:39
 */
@Service
public class BizStaffServiceImpl implements BizStaffService {

	@Autowired
	private BizStaffDao bizStaffDao;

	@Override
	public int add(BizStaff bizStaff) {
		// 设置基本字段信息
		bizStaff.setId(UUIDUtil.getRandomID());
		return bizStaffDao.insert(bizStaff);

	}

	@Override
	public int batchAdd(List<BizStaff> bizStaffList) {
		// 这里没有做基本字段的设置，如有需要请自己实现
		int num = 0;
		int c = 10000;
		int size = bizStaffList.size() / c + 1;
		for (int i = 0; i < size; i++) {
			int begin = i * c;
			int end = (i + 1) * c;
			end = end >= bizStaffList.size() ? bizStaffList.size() : end;
			List<BizStaff> insertList = bizStaffList.subList(begin, end);
			num += bizStaffDao.batchInsert(insertList);
		}
		return num;

	}

	@Override
	public int modifyByMap(BizStaff oldBizStaff, BizStaff newBizStaff) {

		Map<String, Object> modifyMap = null;
		try {
			if (!ModelUtils.isModified(oldBizStaff, newBizStaff)) {
				return MatrixConstance.DML_SUCCESSS;
			}
			modifyMap = ModelUtils.comparePojo2Map(oldBizStaff, newBizStaff);
		} catch (Exception e) {
			throw new GlobleException(SystemErrorCode.DATA_UPDATE_FAIL, e, newBizStaff);
		}
		if (modifyMap.size() > 0) {
			modifyMap.put("id", oldBizStaff.getId());
			bizStaffDao.updateByMap(modifyMap);
		}
		return MatrixConstance.DML_SUCCESSS;
	}

	@Override
	public int modifyByModel(BizStaff bizStaff) {

		return bizStaffDao.updateByModel(bizStaff);

	}

	@Override
	public int remove(List<String> list) {

		return bizStaffDao.deleteByIds(list);

	}

	@Override
	public int removeById(String id) {

		return bizStaffDao.deleteById(id);

	}

	@Override
	public int removeByModel(BizStaff bizStaff) {

		return bizStaffDao.deleteByModel(bizStaff);

	}

	@Override
	public List<BizStaff> findInPage(BizStaff bizStaff, PaginationVO pageVo) {

		return bizStaffDao.selectInPage(bizStaff, pageVo);

	}

	@Override
	public List<BizStaff> findByModel(BizStaff bizStaff) {

		return bizStaffDao.selectByModel(bizStaff);

	}

	@Override
	public int findTotal(BizStaff bizStaff) {

		return bizStaffDao.selectTotalRecord(bizStaff);

	}

	@Override
	public BizStaff findByBusinessId(String businessId) {

		return bizStaffDao.findByBusinessId(businessId);
	}

	@Override
	public BizStaff findById(String id) {

		return bizStaffDao.selectById(id);

	}

	@Override
	public BizStaff findByUserOpenId(String userOpenId) {
		return bizStaffDao.findByUserOpenId(userOpenId);
	}
}